/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package core;

import java.util.Hashtable;

/**
 *
 * @author Kvest
 */
public class RuntimeData
{
    //DriverState constants
    public static final String DRIVER_STATE_FREE = "Free"; // Свободен
    public static final String DRIVER_STATE_DOORDER = "DoOrder"; // выполняет заказ
    public static final String DRIVER_STATE_PAUSE = "Pause"; 
    public static final String DRIVER_STATE_BREAK = "Break";  
    public static final String DRIVER_STATE_OTHER = "Other"; 
    public static final String DRIVER_STATE_INTALKS = "InTalks"; // Занят в переговорах
    public static final String DRIVER_STATE_GETORDER = "GetOrder"; // Получил заказ
    public static final String DRIVER_STATE_ENDRELAY = "EndRelay"; // Конец смены
    public static final String DRIVER_STATE_ENDRELAY_PAUSE = "EndRelay_pause"; 
    
    private int T1,T2,T3;
    //Уникальные данные подключения
    private byte[] guid;
    private int srvID;
    private int peopleID;
    //-----------------------
    private int shownOrderType;
    private int orderArchiveID;
    private boolean exitFlag;
    private int shownOrder;
    private boolean isUsersRequest;
    private String infoTemp;
    private boolean isStateRequest;
    private String newVersionLink;
    private boolean isUpdating;
    private String shownRegion;
    private boolean showFilterForm;
    private int currentPreOrderId = -1;
    private Hashtable givingTime;
    private String driverState;
    private boolean checkNoSubOrderForClose;

    public RuntimeData()
    {
        T1 = 60000;
        T2 = 60000;
        T3 = 60000;
        guid = new byte[16];
        srvID = -1;
        peopleID = -1;
        isUsersRequest = false;
        infoTemp ="";
        isStateRequest = false;
        shownOrderType = 3;
        exitFlag = false;
        isUpdating = false;
        shownRegion = "";
        shownOrder = -1;
        newVersionLink = "";
        orderArchiveID = -1;
        showFilterForm = false;
        givingTime = new Hashtable();
        driverState = DRIVER_STATE_FREE;
        checkNoSubOrderForClose = true;
    }

    public int getT1()
    {
        return T1;
    }

    public void setT1(int value)
    {
        T1 = value;
    }

    public int getT2()
    {
        return T2;
    }

    public void setT2(int value)
    {
        T2 = value;
    }

    public int getT3()
    {
        return T3;
    }

    public void setT3(int value)
    {
        T3 = value;
    }

    public int getSrvID()
    {
        return srvID;
    }

    public void setSrvID(int value)
    {
        srvID = value;
    }

    public void setPeopleID(int value)
    {
        peopleID = value;
    }

    public int getPeopleID()
    {
        return peopleID;
    }

    public byte[] getGUID()
    {
        return guid;
    }

    public void stringToGuid(String val)
    {
        guid = val.getBytes();
    }

    public int getCurrentPreOrderId()
    {
        return currentPreOrderId;
    }

    public void setCurrentPreOrderId(int currentPreOrderId)
    {
        this.currentPreOrderId = currentPreOrderId;
    }

    public boolean isExitFlag()
    {
        return exitFlag;
    }

    public void setExitFlag(boolean exitFlag)
    {
        this.exitFlag = exitFlag;
    }

    public String getInfoTemp()
    {
        return infoTemp;
    }

    public void setInfoTemp(String infoTemp)
    {
        this.infoTemp = infoTemp;
    }

    public boolean isIsStateRequest()
    {
        return isStateRequest;
    }

    public void setIsStateRequest(boolean isStateRequest)
    {
        this.isStateRequest = isStateRequest;
    }

    public boolean isIsUpdating()
    {
        return isUpdating;
    }

    public void setIsUpdating(boolean isUpdating)
    {
        this.isUpdating = isUpdating;
    }

    public boolean isIsUsersRequest()
    {
        return isUsersRequest;
    }

    public void setIsUsersRequest(boolean isUsersRequest)
    {
        this.isUsersRequest = isUsersRequest;
    }

    public String getNewVersionLink()
    {
        return newVersionLink;
    }

    public void setNewVersionLink(String newVersionLink)
    {
        this.newVersionLink = newVersionLink;
    }

    public int getOrderArchiveID()
    {
        return orderArchiveID;
    }

    public void setOrderArchiveID(int orderArchiveID)
    {
        this.orderArchiveID = orderArchiveID;
    }

    public boolean isShowFilterForm()
    {
        return showFilterForm;
    }

    public void setShowFilterForm(boolean showFilterForm)
    {
        this.showFilterForm = showFilterForm;
    }

    public int getShownOrder()
    {
        return shownOrder;
    }

    public void setShownOrder(int shownOrder)
    {
        this.shownOrder = shownOrder;
    }

    public int getShownOrderType()
    {
        return shownOrderType;
    }

    public void setShownOrderType(int shownOrderType)
    {
        this.shownOrderType = shownOrderType;
    }

    public String getShownRegion()
    {
        return shownRegion;
    }

    public void setShownRegion(String shownRegion)
    {
        this.shownRegion = shownRegion;
    }


    public void addGivingTime(int orderID, String time)
    {
        Integer id = new Integer(orderID);
        givingTime.put(id, time);
    }

    public int getGivingTime(int orderID)
    {
        Integer id = new Integer(orderID);
        if (givingTime.containsKey(id))
        {
            String strTime = (String)givingTime.get(id);
            try
            {
                //Возвращаем время в миллисекундах
                return Integer.parseInt(strTime) * 60 *1000;
            }catch(Exception ex)
            {
                //Возвращаем 5 мин, но это не нормально!
                return 5 * 60 * 1000;
            }
        }
        else
        {
            //Возвращаем 5 мин, но это не нормально!
            return 5 * 60 * 1000;
        }
    }

    public String getDriverState() {
        return driverState;
    }
    
    public String getDriverReverseState() {
        return (DRIVER_STATE_FREE.equals(driverState) ? DRIVER_STATE_BREAK : DRIVER_STATE_FREE);
    }

    public void setDriverState(String driverState) {
        this.driverState = driverState;
    }

    public boolean isCheckNoSubOrderForClose() {
        return checkNoSubOrderForClose;
    }

    public void setCheckNoSubOrderForClose(boolean checkNoSubOrderForClose) {
        this.checkNoSubOrderForClose = checkNoSubOrderForClose;
    }
}
